package com.app.mymusic.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.app.mymusic.R;

/**
 * Created by Administrator on 2016-12-26.
 */

public class CheckViews extends View {

    private Paint bgPaint;
    private Paint contentPaint;

    private int mWith,mHeight;
    private Bitmap bitMap;

    public CheckViews(Context context) {
        this(context,null);
    }

    public CheckViews(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CheckViews(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        bgPaint=new Paint();
        bgPaint.setColor(Color.YELLOW);
        bgPaint.setStyle(Paint.Style.FILL);

        contentPaint=new Paint();
        bitMap=BitmapFactory.decodeResource(context.getResources(), R.drawable.more);

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mWith=w;
        mHeight=h;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(mWith/2,mHeight/2);
        canvas.drawCircle(0,0,200,bgPaint);
        bitMap.getWidth();
        Rect srcRect=new Rect(0,0, bitMap.getWidth()/2,bitMap.getHeight());
        Rect dst = new Rect(-200, -200, 200, 200);
        canvas.drawBitmap(bitMap,srcRect,dst,null);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
